package ch.zbw.timeline.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import lombok.Data;

/**
 * Domain class for an employee
 */
@Entity
@SequenceGenerator(name = "id_employee", initialValue = 1, allocationSize = 1)
@Table(name = "employee")
@Data
public class Employee implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id_employee", nullable = false)
	private int id;

	@Column(name = "fk_role", nullable = false)
	private int roleFk;

	@Column(name = "fk_overtime_pool", nullable = true)
	private Integer overTimePoolFk;

	@Column(name = "first_name", nullable = true)
	private String firstName;

	@Column(name = "last_name", nullable = true)
	private String lastName;

	@Column(name = "user_name", nullable = false)
	private String userName;

	@Column(name = "password", nullable = false)
	private String password;

	@Column(name = "comencement_date", nullable = false)
	private Date commencementDate;

	@Column(name = "date_of_birth", nullable = false)
	private Date dateOfBirth;

	@Column(name = "active", nullable = false)
	private int active;

	@Transient
	private Role sessionRole;

	@Transient
	private int employmentStatus;

	@Transient
	private Role role;

	public Employee() {
	}

	public Employee(int roleFk, Integer overTimePoolFk, String firstName,
			String lastName, String userName, String password,
			Date commencementDate, Date dateOfBirth, int active) {
		this.roleFk = roleFk;
		this.overTimePoolFk = overTimePoolFk;
		this.firstName = firstName;
		this.lastName = lastName;
		this.userName = userName;
		this.password = password;
		this.commencementDate = commencementDate;
		this.dateOfBirth = dateOfBirth;
		this.active = active;
	}

	@Transient
	public boolean isAdmin() {
		return (roleFk == 1);
	}
}
